// 220906 liang 设置 echarts 初始化选项
let options = {
  pie: {
    tooltip: {
      show: true,
      textStyle: {
        fontSize: 12,
      },
    },
    series: [
      {
        label: {
          fontSize: 12,
          formatter: '{b}: {c}',
        },
        type: 'pie',
        // center: ['50%', '50%'],
        radius: ['0%', '70%'],
        data: [
          { value: 55, name: '北京', },
          { value: 20, name: '武汉', },
          { value: 10, name: '杭州', },
          { value: 20, name: '广州', },
          { value: 38, name: '上海', }
        ],
      },
    ],
  },
  bar: {
    grid: {
      containLabel: true,
      left: 0,
      top: 20,
      right: 56,
      bottom: 0,
    },
    tooltip: {
      show: true,
      trigger: 'axis',
      // triggerOn: "none",
      axisPointer: {
        type: "shadow"
      },
      textStyle: {
        fontSize: 12,
      },
    },
    
    // dataZoom: {
    //   type: 'slider',
    //   start: 0,
    //   end: 100,
    // },
    xAxis: {
      type: 'category',
      boundaryGap: true,
      data: ['黄逸昊', '卢燕君', '陈晓虹', '梁慧敏', '刘嘉如', '一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', ],
      // show: false
      axisTick: {
        show: false,      // 隐藏x轴刻度
      },
      axisLabel: {        // x轴 label
        fontSize: 10,
        interval: 0,
        hideOverlap: false,
        rotate: '-45',
      },
    },
    yAxis: {
      x: 'center',
      type: 'value',
      splitLine: {
        lineStyle: {
          type: 'dashed'
        },
      },
      // show: false
      axisLabel: {        // y轴 label
        fontSize: 10,
      },
    },
    series: [
      {
        name: '记录数',
        type: 'bar',
        data: [4, 3, 3, 2, 1, 12, 1, 5, 5, 5, 5, 5, 9, ],
        label: {
          show: true,
          position: 'top',
          fontSize: 10,
        },
      },
      {
        name: '周期数',
        type: 'bar',
        data: [5, 7, 1, 9, 6, 12, 1, 7, 7, 4, 1, 6, 12, ],
        label: {
          show: true,
          position: 'top',
          fontSize: 10,
        },
      },
    ],
  },
  line: {
    grid: {
      containLabel: true,
      left: 0,
      top: 20,
      right: 56,
      bottom: 0,
    },
    tooltip: {
      show: true,
      trigger: 'axis',
      textStyle: {
        fontSize: 12,
      },
    },
    xAxis: {
      type: 'category',
      boundaryGap: true,
      data: ['黄逸昊', '卢燕君', '陈晓虹', '梁慧敏', '刘嘉如'],
      // show: false,
      name: 'x轴', // 坐标轴名称显示位置
      nameLocation: 'end',
      nameGap: 5,
      axisTick: {
        show: false,      // 隐藏x轴刻度
      },
      axisLabel: {        // x轴 label
        fontSize: 10,
        interval: 0,
        hideOverlap: false,
      },
    },
    yAxis: {
      // x: 'center',
      type: 'value',
      splitLine: {
        lineStyle: {
          type: 'dashed'
        },
      },
      // show: false
      axisLabel: {        // y轴 label
        fontSize: 10,
      },
    },
    series: [
      {
        name: '记录数',
        type: 'line',
        smooth: true,
        data: [4, 3, 3, 2, 1,],
        label: {
          show: true,
          // distance: 0,
          position: 'top',
          fontSize: 10,
        },
      },
    ],
  },
  ranking: {
    a: 147,
  },
  table: {
    a: 258,
  },
}

let setOption = (item, yData, xData) => {
  let type = item.component_type,
      option = JSON.parse(JSON.stringify(options[type]))
  // console.log(option)
  if(type === 'pie') {    // 饼图
    option.series[0].data = yData
  } else if(type === 'line') {    // 折线图
    option.series = yData
    option.xAxis.data = xData
  } else if(type === 'bar') {     // 柱状图
    option.series = yData
    option.xAxis.data = xData
  }
  return option
}

module.exports = setOption